package io.renren.modules.alarm.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.alarm.entity.MessageEntity;
import io.renren.modules.alarm.service.MessageService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author zhourl
 * @email zhou11258@foxmail.com
 * @date 2022-03-06 20:24:38
 */
@Api("信息接口")
@RestController
@RequestMapping("alarm/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("alarm:message:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = messageService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{messageId}")
    @RequiresPermissions("alarm:message:info")
    public R info(@PathVariable("messageId") Long messageId){
		MessageEntity message = messageService.getById(messageId);

        return R.ok().put("message", message);
    }

    /**
     * 保存
     */
    @ApiOperation("添加信息")
    @PostMapping("/save")
    public R save(@RequestBody MessageEntity message){
		messageService.save(message);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("alarm:message:update")
    public R update(@RequestBody MessageEntity message){
		messageService.updateById(message);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("alarm:message:delete")
    public R delete(@RequestBody Long[] messageIds){
		messageService.removeByIds(Arrays.asList(messageIds));

        return R.ok();
    }


    @GetMapping("/getEcharts")
    public Map<String, Object> getEcharts(){
        Map map = new HashMap();
        map = messageService.getEcharts();
        return map;
    }

}
